package com.muse.appManage.controller;

import com.muse.appManage.service.ManageUserService;
import com.muse.entity.Result;
import com.muse.entity.UserInfo;
import com.muse.interceptor.CurrentContext;
import com.muse.model.AuthRoleParam;
import com.muse.model.ManageUserListParam;
import com.muse.model.UserInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lee
 * Date: 2021/4/27
 * Time: 3:11 下午
 * Description:
 */
@RestController
@RequestMapping(value = "/manage/user")
@Slf4j
public class ManageUserController {
    @Autowired
    private ManageUserService manageUserService;


    @PostMapping("/list")
    public Result<List<UserInfoVo>> list(@RequestBody ManageUserListParam param,
                                         @RequestParam(name = "page", defaultValue = "1") Integer page,
                                         @RequestParam(name = "pageSize", defaultValue = "30") Integer pageSize) {

        log.info("ManageUser list,param={}", param);
        return manageUserService.list(param, page, pageSize);
    }


    @PostMapping("/authRole")
    public Result authRole(@RequestBody AuthRoleParam param) {
        log.info("ManageUser authRole,param={}", param);
        return manageUserService.authRole(param);
    }


    @GetMapping("/me")
    public Result<UserInfoVo> me() {
        Integer id = CurrentContext.getUserId();
        return manageUserService.me(id);
    }
}
